﻿/************************************************************************
 * SMLib - State Model Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     SMLib\Base\IDiGraph.cs
 * Description  :     Interface for Directed Graph
 * Change log   :     -2011: First version (originally, it was part of SimGine library)
 * To Do        :
 ************************************************************************/
using System;
using System.Collections.Generic;

namespace SMLib.Base
{

    /// <summary>
    /// Direct Graph interface. A digraph is a -finite- set of states, each of which has a set of transitions.
    /// Each transition has one (and only one) destination.
    /// <remarks>The DiGraph is designed to facilitate enumaration of the graph. You can 
    /// enumarate all states and then, in each state, you can enumarate all transitions and also
    /// you can find destination of the transition, so it makes us able to easily construct the di-graph</remarks>
    /// </summary>
    /// <typeparam name="STATETYPE">Type of states</typeparam>
    /// <typeparam name="TRANSITIONTYPE">Type of transitions</typeparam>
    public interface IDiGraph<STATETYPE, TRANSITIONTYPE>
    {
        /// <summary>
        /// Get all states
        /// </summary>
        /// <returns>list of all states in the graph</returns>
        List<STATETYPE> GetStates();

        /// <summary>
        /// Access to a particular state of a graph
        /// </summary>
        /// <param name="i">the index</param>
        /// <returns>i-th state/vertex of the graph</returns>
        STATETYPE this[int i]
        {
            get;
        }

        /// <summary>
        /// List of all transitions in a state
        /// <remarks>We assume that this list is by transitions so that a
        /// transition can be added or removed from this list!</remarks>
        /// </summary>
        /// <param name="st">state</param>
        /// <returns>list of transions</returns>
        List<TRANSITIONTYPE> TransitionsOf(STATETYPE st);

        /// <summary>
        /// Destination of a transition
        /// </summary>
        /// <param name="trans"></param>
        /// <returns></returns>
        STATETYPE DestinationOf(TRANSITIONTYPE trans);

        /// <summary>
        /// Find the index of a state
        /// </summary>
        /// <param name="st">the given state</param>
        /// <returns>its index (-1 if not found)</returns>
        int IndexOf(STATETYPE st);

        /// <summary>
        /// Size of graph
        /// </summary>
        int Size
        {
            get;
        }
    }

}
